# -*- coding:utf8 -*-
# __author__ = "zhangying"
# __date__ = "2019/3/11 14:00"
#定位所有元素信息
from util.read_ini import ReadIni


class FindElement(object):
    def __init__(self,driver):
        self.driver = driver

    #找不到元素信息返回none
    def get_element(self,key):
        read_ini =ReadIni()
        data = read_ini.get_value(key)
        by = data.split(">")[0]
        value = data.split(">")[1]
        try:
            if by =='id':
                return self.driver.find_element_by_id(value)
            elif by == 'name':
                return self.driver.find_element_by_name(value)
            elif by == 'className':
                return self.driver.find_element_by_class_name(value)
            else:
                return self.driver.find_element_by_xpath(value)
        except:
            return None


